﻿using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbMoviePreviewTest and is intended
    ///     to contain all TmdbMoviePreviewTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbMoviePreviewTest
    {
        /// <summary>
        ///     A test for TmdbMoviePreview Constructor
        /// </summary>
        [TestMethod]
        public void TmdbMoviePreviewConstructorTest()
        {
            var target = new TmdbMoviePreview();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for BackdropPath
        /// </summary>
        [TestMethod]
        public void BackdropPathTest()
        {
            var target = new TmdbMoviePreview();
            string expected = Guid.NewGuid().ToString();
            string actual;
            target.BackdropPath = expected;
            actual = target.BackdropPath;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for VoteAverage
        /// </summary>
        [TestMethod]
        public void VoteAverageTest()
        {
            var target = new TmdbMoviePreview();
            double expected = new Random().Next( 0, Int32.MaxValue );
            double actual;
            target.VoteAverage = expected;
            actual = target.VoteAverage;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for VoteCount
        /// </summary>
        [TestMethod]
        public void VoteCountTest()
        {
            var target = new TmdbMoviePreview();
            int expected = new Random().Next( 0, Int32.MaxValue );
            int actual;
            target.VoteCount = expected;
            actual = target.VoteCount;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem(@"..\..\TestData\moviePreview.json.txt")]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbMoviePreview();
            var jsonContent = File.ReadAllText("moviePreview.json.txt");
            var actual = await target.DeserializeJson<TmdbMoviePreview>(jsonContent);

            Assert.AreEqual(68726, actual.Id);
            Assert.AreEqual("Pacific Rim", actual.OriginalTitle);
            Assert.AreEqual("/sCJEwEShZvruTpQ2a4yiX3Q9EyZ.jpg", actual.PosterPath);
            Assert.AreEqual("2013-07-12", actual.ReleaseDate);
            Assert.AreEqual("Pacific Rim", actual.Title);

            Assert.AreEqual("/bCJLxmgNaZtpMyWKCCiTYrf3YOT.jpg", actual.BackdropPath);
            Assert.AreEqual(6.5, actual.VoteAverage);
            Assert.AreEqual(113, actual.VoteCount);
        }
    }
}
